<template>
  <c-form-dialog
    ref="form"
    :title="title"
    :visible.sync="innerVisible"
    :form-items="formItems"
    :form-data="registerData"
    :table-name="tableName"
    :table-id="tableId"
    @dismiss="beforeClose"
    @success="handleSuccess"
  ></c-form-dialog>
  <!-- :after-save="afterSave" -->
</template>

<script>
import { mapGetters } from 'vuex'
// import { enumRenewalStatus } from '@/credit/plugins/enum'
import { enumCheckMethod, enumCheckType } from '@/credit/views/city/self/after/enum'
const enumSubmitType = {
  org_gov_ny: 1,
  org_gov_ebb: 1,
  org_credit: 2,
  org_enterprise: 3,
  org_supply_market: 4,
  org_bank: 5,
}

export default {
  components: {},
  props: {
    visible: Boolean,
    relatedId: String,
    tableId: String,
    title: {
      type: String,
      default: '检查登记',
    },
    currentStatus: String,
    changeStatus: Boolean,
    registerData: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      innerVisible: false,
      tableName: 'loan_beh_check',
      formItems: [
        {
          tag: 'input',
          itemAttrs: {
            label: '客户名称',
            rules: [{ required: true, message: '获取名称失败刷新后重试', trigger: 'blur' }],
          },
          attrs: { key: 'customer_name', disabled: true },
        },
        {
          tag: 'date',
          itemAttrs: {
            label: '检查时间',
            rules: [{ required: true, message: '请选择检查时间', trigger: 'change' }],
          },
          attrs: { key: 'check_date', value: '' },
        },
        {
          tag: 'input',
          itemAttrs: {
            label: '检查人员',
          },
          attrs: { key: 'check_person', value: '', disabled: true },
          getAttrs: () => {
            return { value: this.user.realName }
          },
        },
        {
          tag: 'select',
          itemAttrs: {
            label: '检查方式',
            rules: [{ required: true, message: '请选择检查方式', trigger: 'change' }],
          },
          attrs: { key: 'check_method', value: '', options: enumCheckMethod },
        },
        {
          tag: 'select',
          itemAttrs: {
            label: '检查类型',
            rules: [{ required: true, message: '请选择检查类型', trigger: 'change' }],
          },
          attrs: { key: 'check_type', value: '', options: enumCheckType },
        },
        // {
        //   tag: 'select',
        //   itemAttrs: {
        //     label: '项目状态',
        //     rules: [{ required: true, message: '请选择项目状态', trigger: 'change' }]
        //   },
        //   attrs: { clearable: false, key: 'load_beh_status', value: '', options: enumRenewalStatus },
        //   ifRender: () => this.changeStatus
        // },
        {
          tag: 'textarea',
          itemAttrs: {
            label: '检查内容',
            rules: [{ required: true, message: '请输入检查内容', trigger: 'blur' }],
          },
          attrs: { key: 'check_des', value: '', placeholder: '请输入检查内容' },
        },
        {
          tag: 'textarea',
          itemAttrs: {
            label: '检查结论',
            rules: [{ required: true, message: '请输入检查结论', trigger: 'blur' }],
          },
          attrs: { key: 'check_result', value: '', placeholder: '请输入检查结论' },
        },
        {
          tag: 'textarea',
          itemAttrs: {
            label: '处理措施',
            rules: [{ required: true, message: '请输入处理措施', trigger: 'blur' }],
          },
          attrs: { key: 'handle_des', value: '', placeholder: '请输入处理措施' },
        },
        {
          tag: 'upload',
          itemAttrs: { label: '附件' },
          attrs: { key: 'check_attachment', value: '' },
        },
        {
          tag: 'input',
          itemAttrs: { label: 'customer_related_id' },
          attrs: { key: 'customer_related_id', value: '' },
          getValue: () => this.relatedId,
          ifShow: false,
        },
        {
          tag: 'input',
          itemAttrs: { label: 'submit_type' },
          attrs: { key: 'submit_type', value: '' },
          getValue: () => this.submitType,
          ifShow: false,
        },
        {
          tag: 'input',
          itemAttrs: { label: 'submit_client_name' },
          attrs: { key: 'submit_client_name', value: '' },
          getValue: () => this.org.orgName,
          ifShow: false,
        },
        {
          tag: 'input',
          itemAttrs: { label: 'submit_person_name' },
          attrs: { key: 'submit_person_name', value: '' },
          getValue: () => this.user.realName,
          ifShow: false,
        },
      ],
    }
  },
  computed: {
    ...mapGetters(['user', 'org']),
    submitType() {
      return enumSubmitType[this.user.clientOrgClass] || 6
    },
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
  },
  created() {},
  mounted() {},
  methods: {
    beforeClose() {
      this.$emit('update:visible', false)
    },
    handleSuccess() {
      this.beforeClose()
      this.$emit('success', {})
    },
    // afterSave(res, form) {
    //   const status = +form.load_beh_status
    //   if (this.changeStatus && status !== +this.currentStatus) {
    //     this.$api.updateData('credit', 'customer_related', this.relatedId, {
    //       load_beh_status: form.load_beh_status
    //     }).then(() => {
    //       this.$emit('change-status', status)
    //     }).catch(() => {
    //       this.$message.error('更新项目状态失败')
    //     })
    //   }
    // }
  },
}
</script>
<style lang="scss" scoped></style>
